package mblog;

import mblog.base.jsoup.BaiXingUtils;
import mblog.base.utils.AnsjUtils;
import mblog.core.data.Post;
import mblog.core.persist.service.PostService;
import org.springframework.scheduling.annotation.Async;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class PostUtils {

    public static void insertPosts(PostService postService,String jsoupUrl){
        List<Map<String,String>> dataMap =  BaiXingUtils.bxUtils(jsoupUrl);
        if(dataMap!=null){
            dataMap.forEach(mapDate->{
                Post p = new Post();
////        AccountProfile profile = getSubject().getProfile();
                p.setAuthorId(1);
                p.setChannelId(5);
                p.setComments(0);
                p.setCreated(new Date());
                p.setEditor("ueditor");
                p.setFavors(0);
                p.setFeatured(0);
                p.setStatus(0);

                p.setClickUrl(mapDate.get("clickUrl"));
                p.setPrice(mapDate.get("price"));
                String images = mapDate.get("images");
                p.setPictureList(images);
                if(images!=null){
                    p.setThumImage(mapDate.get("picutre"));
                }
                p.setMobile(mapDate.get("mobile"));
                p.setFromSite("百姓网");

                String descs = mapDate.get("descs");
                descs.replaceAll("TA的故事","").replaceAll("收藏","").replaceAll("分享","").replaceAll("举报","");
                p.setSummary(descs);
                p.setContent(descs);

                p.setTitle(mapDate.get("title"));
                String[] strings = new String[]{"n"};//目前只取名词
                String tags = AnsjUtils.analysis(strings,mapDate.get("title"));
                p.setTags(tags);

                p.setViews(1);
                p.setWeight(0);
                p.setOpenInfo(1);
                p.setIsLogin(0);
                p.setLastUpadteTime(new Date());
                p.setOpenInfo(1);
                postService.post(p);
            });
        }


    }

}
